function callback123(json) {
	return json;
}



var tgd = tgd || {};
tgd.Services = tgd.Services || {};
tgd.Services.RESTim = tgd.Services.RESTim || {};

tgd.Services.RESTim.Message = function () {
	tgd.Services.RESTim.Message.prototype.log = function(txt) {
		var now = new Date();
		var div = document.createElement("div");
		var msgLog = document.getElementById("msgLog");
		div.innerHTML = "<span class='date'>" + now.getHours() + ":" + (now.getMinutes() < 10 ? "0" : "") + now.getMinutes() + ":" + (now.getSeconds() < 10 ? "0" : "") + now.getSeconds() + "</span> " + txt;
		msgLog.insertBefore(div, (msgLog.hasChildNodes() ? msgLog.childNodes[0] : null));
	}

	this.log("tgd.Services.RESTim.Message object created");
	this._data = null;

	this.onDelete = null;
	this.onGet = null;
	this.onPost = null;
	this.onPut = null;
	this.Text = "";
	this.id = -1;

	if (tgd.Services.RESTim.Message._initialized === undefined) {

		tgd.Services.RESTim.Message.prototype.get = function() {
			this.log("GET message w/ id [" + this.id + "]");

			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					if (self._request.status == 200) {
						self._data = eval(self._request.responseText);
						self.Text = self._data.Text;
						self.id = self._data.id;
						self.onGet();
					} else {
						self.log("GET message w/ id [" + self.id + "] message returned " + self._request.status + "   " + self._request.statusText);
					}
				}
			}
			this._request.open("GET", "http://timmytooltastix.appspot.com/messages/" + this.id, true);
			this._request.setRequestHeader("If-Modified-Since", "Thu, 17 Jun 1982 00:00:00 GMT");  //IE caching
			//todo:  add headers as needed
			this._request.send(null);
		}

		tgd.Services.RESTim.Message.prototype.save = function() {
			this.log("POST new message with text = [" + this.Text + "]");
			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					self.onPost();
				}
			}
			this._request.open("POST", "http://timmytooltastix.appspot.com/messages", true);
			this._request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			//todo:  add headers as needed
			this._request.send("Text=" + this.Text);
		}

		tgd.Services.RESTim.Message.prototype.update = function() {
			this.log("PUT new message text [" + this.Text + "] for id [" + this.id + "]");

			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					self.onPut();
				}
			}
			this._request.open("PUT", "http://timmytooltastix.appspot.com/messages/" + this.id, true);
			this._request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			//todo:  add headers as needed
			this._request.send("Text=" + this.Text);
		}

		tgd.Services.RESTim.Message.prototype.remove = function() {
			this.log("DELETE message w/ id = [" + this.id + "]");

			var self = this;

			this._request = new XMLHttpRequest();
			this._request.onreadystatechange = function() {
				if (self._request.readyState == 4) {
					self.onDelete();
				}
			}
			this._request.open("DELETE", "http://timmytooltastix.appspot.com/messages/" + this.id, true);
			this._request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			//todo:  add headers as needed
			this._request.send();
		}

		tgd.Services.RESTim.Message._initialized = true;
	}
}
